package com.android.lazysearch;

import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

public class MenuItemsAdapter extends BaseAdapter{

	private Context mContext;
	private ArrayList<Item> items;
	
	public MenuItemsAdapter(Context c, ArrayList<Item> menuItems) 
	{
        mContext = c;
        items = menuItems;
    }

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
//		return 0;
		return items.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
//		return null;
		return items.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		ImageView imageView;
		TextView tv;
		View grid;
		LayoutInflater layoutInflater = null;
//        if (arg1 == null) 
//        {  // if it's not recycled, initialize some attributes
//            imageView = new ImageView(mContext);
//            tv = new TextView(mContext);
//            imageView.setLayoutParams(new GridView.LayoutParams(80, 80));
//            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
//            imageView.setPadding(8, 8, 8, 8);
//        }
			if(arg1==null)
			{
				LayoutInflater mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
				grid = (ViewGroup)mInflater.inflate(R.layout.grid_layout, null);
			}
			else
			{
				grid = (View)arg1;
			}
//        else 
//        {
//            imageView = (ImageView) arg1;
//        }

        Item item = items.get(arg0);
        ((ImageView)grid.findViewById(R.id.imageView1)).setImageResource(item.getItemImage());
        ((TextView)grid.findViewById(R.id.textView1)).setText(item.getItemName());
        return grid;
	}
}
